// news-system-modern/src/store/features/collapsedSlice.ts
import { createSlice } from '@reduxjs/toolkit';
import type { RootState } from '../types';

// 菜单折叠状态切片
const collapsedSlice = createSlice({
  name: 'collapsed',
  initialState: false,
  reducers: {
    setCollapsed: (state, action) => action.payload,
    toggleCollapsed: (state) => !state
  },
});

// 导出actions
export const { setCollapsed, toggleCollapsed } = collapsedSlice.actions;

// 为了兼容旧代码，导出changeCollapsed作为toggleCollapsed的别名
export const changeCollapsed = toggleCollapsed;

// 导出选择器
export const selectCollapsed = (state: RootState) => state.collapsed;

export default collapsedSlice.reducer;